import configparser

from openpyxl.reader.excel import load_workbook

sheet_name = ['商贸管理学院', '通信与电子工程学院', '人文与社会科学学院', '智能制造工程学院']


def summary():
    global sm_max, rw_max, tx_max, zz_max
    cp = configparser.ConfigParser()
    cp.read("config.ini", 'UTF-8')
    sm_number = cp.get("sm", "number")
    rw_number = cp.get("rw", "number")
    tx_number = cp.get("tx", "number")
    zz_number = cp.get("zz", "number")
    total_number = int(sm_number) + int(rw_number) + int(tx_number) + int(zz_number)
    wb = load_workbook('template.xlsx')
    wbe = load_workbook('error.xlsx')
    wse = wbe['未知']
    rowe = wse.max_row
    error_max = rowe - 2
    for sheet in sheet_name:
        ws = wb[sheet]
        row = ws.max_row
        if sheet == '商贸管理学院':
            sm_max = row - 2
        elif sheet == '人文与社会科学学院':
            rw_max = row - 2
        elif sheet == '通信与电子工程学院':
            tx_max = row - 2
        elif sheet == '智能制造工程学院':
            zz_max = row - 2
    total_max = sm_max + rw_max + tx_max + zz_max
    sm_result = sm_max / int(sm_number)
    rw_result = rw_max / int(rw_number)
    tx_result = tx_max / int(tx_number)
    zz_result = zz_max / int(zz_number)
    total_result = total_max / total_number
    print('商贸学院：' + str(sm_max) + '人，占比：' + str('{:.2%}'.format(sm_result)))
    print('人文学院：' + str(rw_max) + '人，占比：' + str('{:.2%}'.format(rw_result)))
    print('通信学院：' + str(tx_max) + '人，占比：' + str('{:.2%}'.format(tx_result)))
    print('智造学院：' + str(zz_max) + '人，占比：' + str('{:.2%}'.format(zz_result)))
    print('未知：'+str(error_max)+'人')
    print('总计完成：'+str(total_max)+'人，占比：' + str('{:.2%}'.format(total_result)))
